package main

import (
	_ "FromNowOnPromote/博客系统/Tblog/models" //初始化mysql连接配置
	_ "FromNowOnPromote/博客系统/Tblog/redis"  //初始化redis连接池
	_ "FromNowOnPromote/博客系统/Tblog/routers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/cors"
)

func main() {
	//跨域访问
	beego.InsertFilter("/*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins: []string{"http://127.0.0.1:8080"},
		//AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Access-Control-Allow-Credentials", "Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "Set-Cookie"},
		ExposeHeaders:    []string{"Content-Length", "Set-Cookie", "Date", "Server"},
		AllowCredentials: true,
	}))

	//设置管理员后台中间件
	//管理员后端只允许Host为127.0.0.2的用户访问
	//beego.InsertFilter("/admin/*",beego.BeforeRouter, func(context *context.Context) {
	//	if context.Request.Host != "127.0.0.2:5000"{
	//		context.ResponseWriter.Status =403
	//		return
	//	}
	//})

	beego.Run()
}
